package won.user;

import won.model.Book;
import won.model.User;
import won.query.UserQuery;

import java.util.Scanner;

import static java.lang.System.out;

public class LoginDisplay {
    public LoginDisplay(){

    }

    public static AbstractUser loginConsole() {
        AbstractUser user = null;
        System.out.println("****************欢迎使用图书管理系统***************");
        while (true) {
            System.out.println("********************账户登录********************");
            out.println("提示：【1】已有账号，请登录 【2】注册学生账号 【3】注册老师账号");
            out.print("请选择方式：");
            Scanner input = new Scanner(System.in);
            String select = input.nextLine();
            out.print("账号：");
            String username = input.nextLine();
            out.print("密码：");
            String password = input.nextLine();
            switch (select) {
                case "1":
                    user = UserManager.userLogin(username, password);
                    break;
                case "2":
                    UserManager.registerUser(username, password,'student');
                    break;
                case "3":
                    UserManager.registerUser(username,password,'teacher');
            }
            if (user != null) {
                out.println("登录成功！");
                break;
            } else {
                out.println("账号或密码有误！");
                out.println("操作选项：【1】重新尝试，请输入1 \t【2】结束运行，请输入Enter键");
                out.print("请选择：");
                String msg = input.nextLine();
                if (!msg.equals("1")) {
                    System.exit(0);
                }
            }
        }
        return user;
    }
}
